const Constant = require("./constant.js");
const AirtelUgxPageTag = require("./airtelUgxPageTag.js");
const RunDefine = require("./baseRunDefine.js");
const SmsUtil = require("./baseSmsUtil.js");
const BaseStringUtil = require("./baseStringUtil.js");

// 一次查询所有标记页状态
const doCheckPageStatus = () => {
    // 状态集合
    let pageStatus = {
        isLoginPage: false,
        isLoginPinPage: false,
        isHomePage: false,
        isBillListPage: false,
        isSendMoneyAccountInputPage: false,
        isSendMoneyConfirmPage: false,
    }

    // 查找所有节点
    let textList = className("TextView").find();
    let editList = className("EditText").find();

    // 判断是否为登录页
    // console.log(Constant.UI_SDK_VERSION + "判断是否为登录页-textList "+ textList.length)
    let loginCon1 = false;
    let loginCon2 = false;
    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(AirtelUgxPageTag.loginPageTag1) !== -1) {
            loginCon1 = true;
            break;
        }
        if (curText.indexOf(AirtelUgxPageTag.loginPageTag2) !== -1) {
            loginCon2 = true;
            break;
        }
        if (loginCon1 && loginCon2) {
            pageStatus.isLoginPage = true;
            break;
        }
    }

    // 判断是否为home页
    // console.log(Constant.UI_SDK_VERSION + "判断是否为HOM页-textList "+ textList.length)
    let homeCon1 = false;
    let homeCon2 = false;
    let homeCon3 = false;
    let homeCon4 = false;
    let homeCon5 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前: " + index + ", 内容: "+ curText)

        if (curText.indexOf(AirtelUgxPageTag.homePageTag1) !== -1) {
            homeCon1 = true;
        }
        else if (curText.indexOf(AirtelUgxPageTag.homePageTag2) !== -1) {
            homeCon2 = true;
        }
        else if (curText.indexOf(AirtelUgxPageTag.homePageTag3) !== -1) {
            homeCon3 = true;
        }
        else if (curText.indexOf(AirtelUgxPageTag.homePageTag4) !== -1) {
            homeCon4 = true;
        }
        else if (curText.indexOf(AirtelUgxPageTag.homePageTag5) !== -1) {
            homeCon5 = true;
        }

        if (homeCon1 && homeCon2 && homeCon3 && homeCon4 && homeCon5) {
            console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前是 首页");
            pageStatus.isHomePage = true;
            // 点击home tab
            click(device.width / 10, device.height - 60);
            sleep(1000);
            break;
        }
    }

    // 判断是否为 send money 页
    let sendMoneyCon1 = false;
    let sendMoneyCon2 = false;
    let sendMoneyCon3 = false;
    let sendMoneyCon4 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(AirtelUgxPageTag.sendMoneyPageTag1) !== -1) {
            sendMoneyCon1 = true

        } else if (curText.indexOf(AirtelUgxPageTag.sendMoneyPageTag2) !== -1) {
            sendMoneyCon2 = true

        } else if (curText.indexOf(AirtelUgxPageTag.sendMoneyPageTag3) !== -1) {
            sendMoneyCon3 = true

        } else if (curText.indexOf(AirtelUgxPageTag.sendMoneyPageTag4) !== -1) {
            sendMoneyCon4 = true
        }

        if (sendMoneyCon1 && sendMoneyCon2 && sendMoneyCon3 && sendMoneyCon4) {
            console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前是 send money 页")
            pageStatus.isSendMoneyAccountInputPage = true;
            break;
        }
    }

    // 判断是否为 send money confirm 页
    let billListCon1 = false;
    let billListCon2 = false;
    let billListCon3 = false;
    let billListCon4 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "doCheckPageStatus-当前: " + index + ", 内容: " + curText);

        if (curText.indexOf(AirtelUgxPageTag.transactionListPageTag1) !== -1) {
            billListCon1 = true;

        } else if (curText.indexOf(AirtelUgxPageTag.transactionListPageTag2) !== -1) {
            billListCon2 = true;

        } else if (curText.indexOf(AirtelUgxPageTag.transactionListPageTag3) !== -1) {
            billListCon3 = true;

        } else if (curText.indexOf(AirtelUgxPageTag.transactionListPageTag4) !== -1) {
            billListCon4 = true;
        }

        if (findTag1 && findTag2 && findTag3 && findTag4) {
            console.log(Constant.UI_SDK_VERSION + "isBillListPage-当前是 bill list 页");
            pageStatus.isBillListPage = true;
            break;
        }
    }

    // 释放缓存
    textList.length = 0;
    textList = null;

    editList.length = 0;
    editList = null;

    return pageStatus;
};

// 监听是否打开了 登录页
const doOpenLoginPage = () => {
    // 循环判断是否为 登录-pin页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
            SmsUtil.syncSmsData();
        }

        // 确认进入了 登录-pin页
        if (isLoginPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 登录页
const isLoginPage = () => {
    let textList = className("TextView").find();
    let loginCon1 = false;
    let loginCon2 = false;

    // console.log(Constant.UI_SDK_VERSION + "判断是否为登录页-textList "+ textList.length)
    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isLoginPage-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(AirtelUgxPageTag.loginPageTag1) !== -1) {
            loginCon1 = true;
            break;
        }
        if (curText.indexOf(AirtelUgxPageTag.loginPageTag2) !== -1) {
            loginCon2 = true;
            break;
        }
        if (loginCon1 && loginCon2) {
            console.log(Constant.UI_SDK_VERSION + "isLoginPage-当前是登录页");
            textList.length = 0;
            textList = null;
            return true;
        }
    }

    textList.length = 0;
    textList = null;
    console.log(Constant.UI_SDK_VERSION + "isLoginPage-当前不是登录页")
    return false;
}

// 监听是否打开了 登录-pin页
const doOpenLoginPinPage = () => {
    // 循环判断是否为 登录-pin页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
            SmsUtil.syncSmsData();
        }

        // 确认进入了 登录-pin页
        if (isLoginPinPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 登录-pin页
const isLoginPinPage = () => {
    let textList = className("TextView").find();

    // console.log(Constant.UI_SDK_VERSION + "判断是否为PIN页-editList "+ editList.length)
    let pinCon1 = false;
    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isLoginPinPage-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(AirtelUgxPageTag.pinPageTag2) !== -1) {
            console.log(Constant.UI_SDK_VERSION + "isLoginPinPage-当前是登录-pin页");
            textList.length = 0;
            textList = null;
            return true;
            break;
        }
    }

    textList.length = 0;
    textList = null;

    console.log(Constant.UI_SDK_VERSION + "isLoginPinPage-当前不是登录-pin页")
    return false;
}

// 监听是否打开了 首页
const doOpenHomePage = () => {
    // 循环判断是否为 首页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
            SmsUtil.syncSmsData();
        }

        // 确认进入了 Send Money 页
        if (isHomePage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为首页
const isHomePage = () => {
    let textList = className("TextView").find();

    let homeCon1 = false;
    let homeCon2 = false;
    let homeCon3 = false;
    let homeCon4 = false;
    let homeCon5 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isHomePage-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(AirtelUgxPageTag.homePageTag1) !== -1) {
            homeCon1 = true;
        }
        else if (curText.indexOf(AirtelUgxPageTag.homePageTag2) !== -1) {
            homeCon2 = true;
        }
        else if (curText.indexOf(AirtelUgxPageTag.homePageTag3) !== -1) {
            homeCon3 = true;
        }
        else if (curText.indexOf(AirtelUgxPageTag.homePageTag4) !== -1) {
            homeCon4 = true;
        }
        else if (curText.indexOf(AirtelUgxPageTag.homePageTag5) !== -1) {
            homeCon5 = true;
        }

        if (homeCon1 && homeCon2 && homeCon3 && homeCon4 && homeCon5) {
            console.log(Constant.UI_SDK_VERSION + "isHomePage-当前是 首页");
            textList.length = 0;
            textList = null;
            return true;
        }
    }

    textList.length = 0;
    textList = null;
    console.log(Constant.UI_SDK_VERSION + "isHomePage-当前不是 首页")
    return false;
}

// 监听是否打开了 airtel money 页
const doOpenTabAirtelMoneyPage = () => {
    // 循环判断是否为 服务页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
            SmsUtil.syncSmsData();
        }

        // 确认进入了 Send Money 页
        if (isTabAirtelMoneyPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 airtel money 页
const isTabAirtelMoneyPage = () => {
    let textList = className("TextView").find();

    let homeCon1 = false;
    let homeCon2 = false;
    let homeCon3 = false;
    let homeCon4 = false;
    let homeCon5 = false;

    let airtelMoneyCon1 = false;
    let airtelMoneyCon2 = false;
    let airtelMoneyCon3 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isAirtelMoneyPage-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(AirtelUgxPageTag.homePageTag1) !== -1) {
            homeCon1 = true;
        }
        else if (curText.indexOf(AirtelUgxPageTag.homePageTag2) !== -1) {
            homeCon2 = true;
        }
        else if (curText.indexOf(AirtelUgxPageTag.homePageTag3) !== -1) {
            homeCon3 = true;
        }
        else if (curText.indexOf(AirtelUgxPageTag.homePageTag4) !== -1) {
            homeCon4 = true;
        }
        else if (curText.indexOf(AirtelUgxPageTag.homePageTag5) !== -1) {
            homeCon5 = true;
        }

        if (curText.indexOf(AirtelUgxPageTag.tabAirtelMoneyPageTag1) !== -1) {
            airtelMoneyCon1 = true
        }
        if (curText.indexOf(AirtelUgxPageTag.tabAirtelMoneyPageTag2) !== -1) {
            airtelMoneyCon2 = true
        }
        if (curText.indexOf(AirtelUgxPageTag.tabAirtelMoneyPageTag3) !== -1) {
            airtelMoneyCon3 = true
        }

        if (homeCon1 && homeCon2 && homeCon3 && homeCon4 && homeCon5 && airtelMoneyCon1 && airtelMoneyCon2 && airtelMoneyCon3) {
            console.log(Constant.UI_SDK_VERSION + "isAirtelMoneyPage-当前是 airtel money页")
            textList.length = 0;
            textList = null;
            return true;
        }
    }

    textList.length = 0;
    textList = null;
    console.log(Constant.UI_SDK_VERSION + "isAirtelMoneyPage-当前不是 airtel money页")
    return false;
}

// 监听是否打开了 more 页
const doOpenTabMorePage = () => {
    // 循环判断是否为 more页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
            SmsUtil.syncSmsData();
        }

        // 确认进入了 more 页
        if (isTabMorePage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 tab more 页
const isTabMorePage = () => {
    let textList = className("TextView").find();

    let homeCon1 = false;
    let homeCon2 = false;
    let homeCon3 = false;
    let homeCon4 = false;
    let homeCon5 = false;

    let moreCon1 = false;
    let moreCon2 = false;
    let moreCon3 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isAirtelMoneyPage-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(AirtelUgxPageTag.homePageTag1) !== -1) {
            homeCon1 = true;
        }
        else if (curText.indexOf(AirtelUgxPageTag.homePageTag2) !== -1) {
            homeCon2 = true;
        }
        else if (curText.indexOf(AirtelUgxPageTag.homePageTag3) !== -1) {
            homeCon3 = true;
        }
        else if (curText.indexOf(AirtelUgxPageTag.homePageTag4) !== -1) {
            homeCon4 = true;
        }
        else if (curText.indexOf(AirtelUgxPageTag.homePageTag5) !== -1) {
            homeCon5 = true;
        }

        if (curText.indexOf(AirtelUgxPageTag.tabMorePageTag1) !== -1) {
            moreCon1 = true

        } else if (curText.indexOf(AirtelUgxPageTag.tabMorePageTag2) !== -1) {
            moreCon2 = true

        } else if (curText.indexOf(AirtelUgxPageTag.tabMorePageTag3) !== -1) {
            moreCon3 = true
        }

        if (homeCon1 && homeCon2 && homeCon3 && homeCon4 && moreCon1 && moreCon2 && moreCon3) {
            console.log(Constant.UI_SDK_VERSION + "isTabMorePage-当前是 more页")
            textList.length = 0;
            textList = null;
            return true;
        }
    }

    textList.length = 0;
    textList = null;
    console.log(Constant.UI_SDK_VERSION + "isTabMorePage-当前不是 more页")
    return false;
}

// 监听是否打开了 more airtel money services 页
const doOpenTabMoreAirtelMoneyServicesPage = () => {
    // 循环判断是否为 more页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
            SmsUtil.syncSmsData();
        }

        // 确认进入了 more 页
        if (isTabMoreAirtelMoneyServicesPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 tab more airtel money services 页
const isTabMoreAirtelMoneyServicesPage = () => {
    let textList = className("TextView").find();

    let homeCon1 = false;
    let homeCon2 = false;
    let homeCon3 = false;
    let homeCon4 = false;
    let homeCon5 = false;

    let moreCon1 = false;
    let moreCon2 = false;
    let moreCon3 = false;
    let moreCon4 = false;
    let moreCon5 = false;
    let moreCon6 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isTabMoreAirtelMoneyServicesPage-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(AirtelUgxPageTag.homePageTag1) !== -1) {
            homeCon1 = true;
        }
        else if (curText.indexOf(AirtelUgxPageTag.homePageTag2) !== -1) {
            homeCon2 = true;
        }
        else if (curText.indexOf(AirtelUgxPageTag.homePageTag3) !== -1) {
            homeCon3 = true;
        }
        else if (curText.indexOf(AirtelUgxPageTag.homePageTag4) !== -1) {
            homeCon4 = true;
        }
        else if (curText.indexOf(AirtelUgxPageTag.homePageTag5) !== -1) {
            homeCon5 = true;
        }

        if (curText.indexOf(AirtelUgxPageTag.tabMorePageTag1) !== -1) {
            moreCon1 = true;

        } else if (curText.indexOf(AirtelUgxPageTag.tabMorePageTag2) !== -1) {
            moreCon2 = true;

        } else if (curText.indexOf(AirtelUgxPageTag.tabMorePageTag3) !== -1) {
            moreCon3 = true;

        } else if (curText.indexOf(AirtelUgxPageTag.tabMorePageTag4) !== -1) {
            moreCon4 = true;

        } else if (curText.indexOf(AirtelUgxPageTag.tabMorePageTag5) !== -1) {
            moreCon5 = true;

        } else if (curText.indexOf(AirtelUgxPageTag.tabMorePageTag6) !== -1) {
            moreCon6 = true;
        }

        if (homeCon1 && homeCon2 && homeCon3 && homeCon4 && homeCon5 && moreCon1 && moreCon2 && moreCon3 && moreCon4 && moreCon5 && moreCon6) {
            console.log(Constant.UI_SDK_VERSION + "isTabMoreAirtelMoneyServicesPage-当前是 more airtel money services页")
            textList.length = 0;
            textList = null;
            return true;
        }
    }

    textList.length = 0;
    textList = null;
    console.log(Constant.UI_SDK_VERSION + "isTabMoreAirtelMoneyServicesPage-当前不是 more airtel money services页")
    return false;
}

// 监听是否打开了 流水页
const doOpenBillListPage = () => {
    // 循环判断是否为 流水页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
            SmsUtil.syncSmsData();
        }

        // 确认进入了 流水页
        if (isBillListPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 bill list 页
const isBillListPage = () => {
    let textList = className("TextView").find();

    let findTag1 = false;
    let findTag2 = false;
    let findTag3 = false;
    let findTag4 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isBillListPage-当前: " + index + ", 内容: " + curText);

        if (curText.indexOf(AirtelUgxPageTag.transactionListPageTag1) !== -1) {
            findTag2 = true;

        } else if (curText.indexOf(AirtelUgxPageTag.transactionListPageTag2) !== -1) {
            findTag3 = true;

        } else if (curText.indexOf(AirtelUgxPageTag.transactionListPageTag3) !== -1) {
            findTag4 = true;

        } else if (curText.indexOf(AirtelUgxPageTag.transactionListPageTag4) !== -1) {
            findTag4 = true;
        }

        if (findTag1 && findTag2 && findTag3 && findTag4) {
            console.log(Constant.UI_SDK_VERSION + "isBillListPage-当前是 bill list 页");
            textList.length = 0;
            textList = null;
            return true;
        }
    }

    textList.length = 0;
    textList = null;
    console.log(Constant.UI_SDK_VERSION + "isBillListPage-当前不是 bill list 页")
    return false;
}

/** 是否打开了 send money 页 */
const doOpenSendMoneyPage = () => {
    // 循环判断是否为 流水页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
            SmsUtil.syncSmsData();
        }

        // 确认进入了页面
        if (isSendMoneyPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 send money 页
const isSendMoneyPage = () => {
    let textList = className("TextView").find();

    let sendMoneyCon1 = false;
    let sendMoneyCon2 = false;
    let sendMoneyCon3 = false;
    let sendMoneyCon4 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isSendMoneyPage-当前: " + index + ", 内容: " + curText);

        if (curText.indexOf(AirtelUgxPageTag.sendMoneyPageTag1) !== -1) {
            sendMoneyCon1 = true;

        } else if (curText.indexOf(AirtelUgxPageTag.sendMoneyPageTag2) !== -1) {
            sendMoneyCon2 = true;

        } else if (curText.indexOf(AirtelUgxPageTag.sendMoneyPageTag3) !== -1) {
            sendMoneyCon3 = true;

        } else if (curText.indexOf(AirtelUgxPageTag.sendMoneyPageTag4) !== -1) {
            sendMoneyCon4 = true;
        }

        if (sendMoneyCon1 && sendMoneyCon2 && sendMoneyCon3 && sendMoneyCon4) {
            console.log(Constant.UI_SDK_VERSION + "isSendMoneyPage-当前是 send money 页");
            textList.length = 0;
            textList = null;
            return true;
        }
    }

    textList.length = 0;
    textList = null;
    console.log(Constant.UI_SDK_VERSION + "isSendMoneyPage-当前不是 send money 页")
    return false;
}

// 监听是否打开了 Send Money input account 页
const doOpenInputTargetAccountPage = () => {
    // 循环判断是否为 Send Money input account 页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
            SmsUtil.syncSmsData();
        }

        // 确认进入了 Send Money input account 页
        if (isInputTargetAccountPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 Send Money input account 页
const isInputTargetAccountPage = () => {
    // let textList = className("TextView").find();
    let editList = className("EditText").find();

    let findTag1 = false;
    let findTag2 = false;
    let findTag3 = false;

    for (let index = 0; index < editList.length; index++) {
        let tv = editList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "当前: " + index + ", 内容: "+ curText)

        if (curText.indexOf(AirtelUgxPageTag.sendMoneyAccountInputPageTag1) !== -1) {
            findTag1 = true
        }
        if (curText.indexOf(AirtelUgxPageTag.sendMoneyAccountInputPageTag2) !== -1) {
            findTag2 = true
        }
        if (curText.indexOf(AirtelUgxPageTag.sendMoneyAccountInputPageTag3) !== -1) {
            findTag3 = true
        }
    }

    if (findTag1 && findTag2 && findTag3) {
        console.log(Constant.UI_SDK_VERSION + "isInputTargetAccountPage-当前是 Send Money input account 页")
        // textList.length = 0;
        // textList = null;
        editList.length = 0;
        editList = null;
        return true;
    }

    // textList.length = 0;
    // textList = null;
    editList.length = 0;
    editList = null;
    console.log(Constant.UI_SDK_VERSION + "isInputTargetAccountPage-当前不是 Send Money input account 页")
    return false;
}

// 监听是否打开了 Send Money Amount Input 页
const doOpenInputTargetAmountPage = () => {
    // 循环判断是否为 Send Money Amount Input 页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
            SmsUtil.syncSmsData();
        }

        // 确认进入了 Send Money Amount Input 页
        if (isInputTargetAmountPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 Send Money account input 页
const isInputTargetAmountPage = () => {
    let textList = className("TextView").find();

    let findTag1 = false;
    let findTag2 = false;
    let findTag3 = false;
    let findTag4 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isInputTargetAmountPage-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(AirtelUgxPageTag.sendMoneyAccountInputDonePageTag1) !== -1) {
            findTag1 = true

        } else if (curText.indexOf(AirtelUgxPageTag.sendMoneyAccountInputDonePageTag2) !== -1) {
            findTag2 = true

        } else if (curText.indexOf(AirtelUgxPageTag.sendMoneyAccountInputDonePageTag3) !== -1) {
            findTag3 = true

        } else if (curText.indexOf(AirtelUgxPageTag.sendMoneyAccountInputDonePageTag4) !== -1) {
            findTag4 = true
        }

        if (findTag1 && findTag2 && findTag3 && findTag4) {
            console.log(Constant.UI_SDK_VERSION + "isInputTargetAmountPage-当前是 Send Money amount input 页");
            textList.length = 0;
            textList = null;
            editList.length = 0;
            editList = null;
            return true;
        }
    }

    textList.length = 0;
    textList = null;
    editList.length = 0;
    editList = null;
    console.log(Constant.UI_SDK_VERSION + "isInputTargetAmountPage-当前不是 Send Money amount input 页")
    return false;
}

// 监听是否打开了 Send Money Confirm 页
const doOpenSendMoneyConfirmPage = () => {
    // 循环判断是否为 Send Money Confirm 页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
            SmsUtil.syncSmsData();
        }

        // 确认进入了 Send Money Confirm 页
        if (isSendMoneyConfirmPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 Send Money confirm 页
const isSendMoneyConfirmPage = () => {
    console.log(Constant.UI_SDK_VERSION + "isSendMoneyConfirmPage-开始判断 是否为 Send Money confirm 页")
    let textList = className("TextView").find();

    let findTag1 = false;
    let findTag2 = false;
    let findTag3 = false;
    let findTag4 = false;
    let findTag5 = false;
    let findTag6 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(AirtelUgxPageTag.sendMoneyConfirmPageTag1) !== -1) {
            findTag1 = true
        }
        else if (curText.indexOf(AirtelUgxPageTag.sendMoneyConfirmPageTag2) !== -1) {
            findTag2 = true
        }
        else if (curText.indexOf(AirtelUgxPageTag.sendMoneyConfirmPageTag3) !== -1) {
            findTag3 = true
        }
        else if (curText.indexOf(AirtelUgxPageTag.sendMoneyConfirmPageTag4) !== -1) {
            findTag4 = true
        }
        else if (curText.indexOf(AirtelUgxPageTag.sendMoneyConfirmPageTag5) !== -1) {
            findTag5 = true
        }
        else if (curText.indexOf(AirtelUgxPageTag.sendMoneyConfirmPageTag6) !== -1) {
            findTag6 = true
        }

        if (findTag1 && findTag2 && findTag3 && findTag4 && findTag5 && findTag6) {
            console.log(Constant.UI_SDK_VERSION + "isSendMoneyConfirmPage-当前是 Send Money confirm 页");
            textList.length = 0;
            textList = null;
            return true;
        }
    }

    textList.length = 0;
    textList = null;
    console.log(Constant.UI_SDK_VERSION + "isSendMoneyConfirmPage-当前不是 Send Money confirm 页")
    return false;
}

// 监听是否打开了 Send Money password 页
const doOpenSendMoneyPasswordPage = () => {
    // 循环判断是否为 Send Money password 页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
            SmsUtil.syncSmsData();
        }

        // 确认进入了 Send Money password 页
        if (isSendMoneyPasswordPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 Send Money password 页
const isSendMoneyPasswordPage = () => {
    let textList = className("TextView").find();

    // console.log(Constant.UI_SDK_VERSION + "判断是否为PIN页-editList "+ editList.length)
    let pinCon1 = false;
    let pinCon2 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isSendMoneyPasswordPage-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(AirtelUgxPageTag.pinPageTag2) !== -1) {
            pinCon1 = true;
        }
        if (curText.indexOf(AirtelUgxPageTag.pinPageTag3) !== -1) {
            pinCon2 = true;
        }
        if (pinCon1 && pinCon2) {
            console.log(Constant.UI_SDK_VERSION + "isSendMoneyPasswordPage-当前是登录-pin页");
            textList.length = 0;
            textList = null;
            return true;
        }
    }

    textList.length = 0;
    textList = null;

    console.log(Constant.UI_SDK_VERSION + "isSendMoneyPasswordPage-当前不是登录-pin页")
    return false;
}

// 监听是否打开了转账预校验页，通常是检验失败页
const doOpenSendMoneyPreCheckPage = () => {
    // 结果集合
    let sendResult = {
        isSuccess: false,
        isFail: false
    };
    // 循环判断是否为 Send Money Result 页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
            SmsUtil.syncSmsData();
        }

        // 确认进入了 Send Money Success 页
        if (isSendMoneyConfirmPage()) {
            sendResult.isSuccess = true;
            sendResult.isFail = false;
            break;
        }

        // 确认进入了 Send Money Fail 页
        if (isSendMoneyFailPage()) {
            sendResult.isSuccess = false;
            sendResult.isFail = true;
            break;
        }

        sleep(1 * 1000);
    }

    return sendResult;
};

// 监听是否打开了 Send Money Result 页
const doOpenSendMoneyResultPage = () => {
    // 结果集合
    let sendResult = {
        isSuccess: false,
        isFail: false
    };
    // 循环判断是否为 Send Money Result 页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryCount; rIndex++) {
        // 计算公式： (n+1)%10 = 0 时上报短信
        if (((rIndex + 1) % 10) === 0) {
            // 上传短信
            SmsUtil.syncSmsData();
        }

        // 确认进入了 Send Money Success 页
        if (isSendMoneySuccessPage()) {
            sendResult.isSuccess = true;
            sendResult.isFail = false;
            break;
        }

        // 确认进入了 Send Money Fail 页
        if (isSendMoneyFailPage()) {
            sendResult.isSuccess = false;
            sendResult.isFail = true;
            break;
        }

        sleep(1 * 1000);
    }

    return sendResult;
};

// 是否为 Send Money Success 页
const isSendMoneySuccessPage = () => {
    let textList = className("TextView").find();

    let findTag1 = false;
    let findTag2 = false;
    let findTag3 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        console.log(Constant.UI_SDK_VERSION + "isSendMoneySuccessPage-当前: " + index + ", 内容: " + curText)

        if (curText.indexOf(AirtelUgxPageTag.sendMoneySuccessPageTag1) !== -1) {
            findTag1 = true
        }
        if (curText.indexOf(AirtelUgxPageTag.sendMoneySuccessPageTag2) !== -1) {
            findTag2 = true
        }
        if (curText.indexOf(AirtelUgxPageTag.sendMoneySuccessPageTag3) !== -1) {
            findTag3 = true
        }

        if (findTag1 && findTag2 && findTag3) {
            console.log(Constant.UI_SDK_VERSION + "isSendMoneySuccessPage-当前是 Send Money Success 页");
            textList.length = 0;
            textList = null;
            return true;
        }
    }

    textList.length = 0;
    textList = null;
    console.log(Constant.UI_SDK_VERSION + "isSendMoneySuccessPage-当前不是 Send Money Success 页")
    return false;
}

// 监听是否打开了 Send Money Mtn Fail 页
const doOpenSendMoneyMtnFailPage = () => {
    // 停留2秒缓冲
    sleep(2000);

    // 循环判断是否为 Send Money Mtn Fail 页
    for (let rIndex = 0; rIndex < RunDefine.loopQueryTransferFailCount; rIndex++) {
        // 确认进入了 Send Money Mtn Fail 页
        if (isSendMoneyFailPage()) {
            return true;
        }

        sleep(1 * 1000);
    }

    return false;
};

// 是否为 Send Money Fail 页
const isSendMoneyFailPage = () => {
    let textList = className("TextView").find();

    // 先判断是否出现服务器错误提示
    // let serErrCon1 = false;
    // for (let index = 0; index < textList.length; index++) {
    //     let tv = textList[index];
    //     let curText = tv.text() || ""
    //     // console.log(Constant.UI_SDK_VERSION + "当前: " + index + ", 内容: "+ curText)

    //     if (curText.indexOf(AirtelUgxPageTag.networkErrAlterTag1) !== -1) {
    //         console.log(Constant.UI_SDK_VERSION + "isSendMoneyFailPage-当前出现服务器错误提示.")
    //         serErrCon1 = true;
    //         break;
    //     }
    // }
    // if (serErrCon1) {
    //     click(AirtelUgxPageTag.networkErrAlterTag2);
    //     sleep(500);
    //     click(AirtelUgxPageTag.networkErrAlterTag2);
    //     sleep(1000);
    //     textList.length = 0;
    //     textList = null;
    //     textList = className("TextView").find();
    // }

    let findTag1 = false;
    // let findTag2 = false;
    // let findTag3 = false;

    for (let index = 0; index < textList.length; index++) {
        let tv = textList[index];
        let curText = tv.text() || ""
        // console.log(Constant.UI_SDK_VERSION + "当前: " + index + ", 内容: "+ curText)

        if (curText.indexOf(AirtelUgxPageTag.sendMoneyFailPageTag1) !== -1) {
            findTag1 = true;
            break;
        }
        // if (curText.indexOf(AirtelUgxPageTag.sendMoneyMtnFailPageTag2) !== -1) {
        //     findTag2 = true
        // }
        // if (curText.indexOf(AirtelUgxPageTag.sendMoneyMtnFailPageTag3) !== -1) {
        //     findTag3 = true
        // }
        // if (curText.indexOf(PageTag.sendMoneyMtnFailPageTag3) !== -1) {
        //     findTag3 = true
        // }
    }

    if (findTag1) {
        console.log(Constant.UI_SDK_VERSION + "isSendMoneyFailPage-当前是 Send Money Fail 页")
        textList.length = 0;
        textList = null;
        return true;
    }

    textList.length = 0;
    textList = null;
    console.log(Constant.UI_SDK_VERSION + "isSendMoneyFailPage-当前不是 Send Money Mtn Fail 页")
    return false;
}

// 是否为 月份字符串
const isMonthScaleWords = (word) => {
    if (word) {
        if (word.startsWith("Jan")) {
            return true;
        }
        if (word.startsWith("Feb")) {
            return true;
        }
        if (word.startsWith("Mar")) {
            return true;
        }
        if (word.startsWith("Apr")) {
            return true;
        }
        if (word.startsWith("May")) {
            return true;
        }
        if (word.startsWith("Jun")) {
            return true;
        }
        if (word.startsWith("Jul")) {
            return true;
        }
        if (word.startsWith("Aug")) {
            return true;
        }
        if (word.startsWith("Sep")) {
            return true;
        }
        if (word.startsWith("Oct")) {
            return true;
        }
        if (word.startsWith("Nov")) {
            return true;
        }
        if (word.startsWith("Dec")) {
            return true;
        }
    }
    return false;
};

module.exports = {
    doCheckPageStatus: doCheckPageStatus,
    doOpenLoginPage: doOpenLoginPage,
    doOpenLoginPinPage: doOpenLoginPinPage,

    doOpenHomePage: doOpenHomePage,

    doOpenTabAirtelMoneyPage: doOpenTabAirtelMoneyPage,
    doOpenSendMoneyPage: doOpenSendMoneyPage,

    doOpenTabMorePage: doOpenTabMorePage,
    doOpenTabMoreAirtelMoneyServicesPage: doOpenTabMoreAirtelMoneyServicesPage,
    doOpenBillListPage: doOpenBillListPage,

    doOpenInputTargetAccountPage: doOpenInputTargetAccountPage,
    isSendMoneyMtnPage: isInputTargetAccountPage,
    doOpenInputTargetAmountPage: doOpenInputTargetAmountPage,
    isInputTargetAmountPage: isInputTargetAmountPage,
    doOpenSendMoneyConfirmPage: doOpenSendMoneyConfirmPage,
    doOpenSendMoneyPasswordPage: doOpenSendMoneyPasswordPage,
    isSendMoneyPasswordPage: isSendMoneyPasswordPage,
    doOpenSendMoneyResultPage: doOpenSendMoneyResultPage,

    doOpenSendMoneyPreCheckPage: doOpenSendMoneyPreCheckPage,
    isSendMoneyConfirmPage: isSendMoneyConfirmPage,
    isSendMoneyMtnSuccessPage: isSendMoneySuccessPage,
    doOpenSendMoneyMtnFailPage: doOpenSendMoneyMtnFailPage,
    isSendMoneyMtnFailPage: isSendMoneyFailPage,
    isMonthScaleWords: isMonthScaleWords
};